package com.rent.auth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.rent.auth.mapper.RolePermissionMapper;
import com.rent.auth.model.Role;
import com.rent.auth.model.RolePermission;
import com.rent.auth.service.IRolePermissionService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 后台用户权限表 服务实现类
 * </p>
 *
 * @author zn
 * @since 2025-01-17
 */
@Service
public class RolePermissionServiceImpl extends MyBaseService<RolePermissionMapper, RolePermission, Integer> implements IRolePermissionService {

    @Override
    public List<RolePermission> selectListByRoles(List<Role> roleList) {
        if (CollectionUtils.isEmpty(roleList)) return null;
        List<Integer> roleIds = new ArrayList<>();
        for (Role role : roleList) {
            roleIds.add(role.getId());
        }
        LambdaQueryWrapper<RolePermission> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByAsc(RolePermission::getId);
        wrapper.in(RolePermission::getRoleId, roleIds);
        wrapper.eq(RolePermission::getStatus, 1);
        return getBaseMapper().selectList(wrapper);
    }
}
